import React, { useRef } from 'react';
import { connect } from 'umi';
import { useNeedManage } from '../common/useNeedManage';
import { SchemaManage } from '@/components/SchemaComponent';
import { XQBZ_STATE } from '../common/Format';
import { NeedManageAPI } from '../common/type';
import { RevokeModal } from '../../Acomponents/RevokeModal';
import { RemoveModal } from '../../Acomponents/RemoveModal';
import { CollectModal } from './CollectModal';

const NeedManageView: React.FC<NeedManageAPI.IManageType> = ({ locationProps, curRes }) => {
  // 管理页配置项
  const { tableProps, searchProps, actionList, change, state } = useNeedManage({ curRes, locationProps });
  const { onChangeManageCancelState, setIsShowCollect, reloadRequests } = change;
  const { isShowManageCancel, isShowCollect } = state;

  return (
    <>
      <SchemaManage ref={useRef()} searchProps={searchProps} actionList={actionList} tableProps={tableProps} />

      {/* 汇总弹窗 */}
      {isShowCollect?.isShow && (
        <CollectModal
          bodyWidth={0.3}
          requestUrl={'/purchaseNeedController/collect'}
          onClose={() => setIsShowCollect({})}
          modalTitle={'汇总提示'}
          reqBody={{ purchaseNeedIds: isShowCollect?.selectedRowKeys }}
          reloadRequest={reloadRequests}
          modalTip={
            <div style={{ color: '#000', textAlign: 'center', lineHeight: '50px' }}>
              <div>
                请确认是否汇总【<span style={{ color: 'red', fontWeight: 600 }}>{isShowCollect?.selectedRowKeys?.length || 0}</span>】条月度计划
              </div>
              <div>此操作后不可恢复！</div>
            </div>
          }
        />
      )}

      {/* 删除弹窗 */}
      {isShowManageCancel?.isShow && (
        <RemoveModal
          resObj={isShowManageCancel?.resObj}
          revokeRequestUrl={'/purchaseNeedController/delPurchaseNeed'}
          onClose={() => onChangeManageCancelState({})}
          reqBody={{}}
          modalTitle={'删除提示'}
          bodyWidth={0.3}
          modalTip={
            <div style={{ color: '#000', textAlign: 'center', lineHeight: '50px' }}>
              <div>
                请确认是否删除【<span style={{ color: 'red' }}>{isShowManageCancel?.resObj?.needName}</span>】
              </div>
              <div>此操作后不可恢复！</div>
            </div>
          }
          reloadRequest={reloadRequests}
        />
      )}

      {/* 作废弹窗 */}
      {/* {
        isShowManageCancel?.isShow &&
        <ManageCancelModal
          onClose={onChangeManageCancelState}
          onSubmit={cancelSubmit}
          form={cancelForm}
          needInfo={needInfo}
        />
      } */}
      {/* {isShowManageCancel?.isShow && (
        <CancelModal
          checkRows={needInfo}
          cancelTypeDic={ILoadMapTypeAll.NEED_CANCEL}
          cancelFormTypeRequired={true}
          cancelFormReasonRequired={true}
          modalTitle={'作废需求'}
          cancelRequestUrl={'/purchaseNeedController/cancel'}
          cancelRequestBody={{ state: XQZF_STATE() }}
          reloadManage={cancelSubmit}
          cancelRequestType="POST"
          onClose={() => {
            onChangeManageCancelState({ isShow: false, resObj: null });
          }}
        />
      )} */}

      {/* 撤销 */}
      {/* {revokeState?.isShow && (
        <RevokeModal
          resObj={revokeState?.resObj}
          revokeRequestUrl={'/purchaseNeedController/invalid'}
          onClose={() => setRevokeState({})}
          reqBody={{ state: XQBZ_STATE() }}
          modalTip={
            <div style={{ color: '#000' }}>
              确认是否撤销【<span style={{ color: 'red' }}>{revokeState?.resObj?.needName}</span>】, 撤销后可重新提交！
            </div>
          }
          reloadRequest={reloadRequests}
        />
      )} */}
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(NeedManageView);
